let express = require("express");
let mongoose = require("mongoose");
let userRouter = require("./routers/user");
let doctorRouter = require("./routers/doctor");
let cateRouter = require("./routers/cate");
let newsinfoRouter = require("./routers/newsinfo");
let patientRouter = require("./routers/patient");
let followRouter = require("./routers/follow");
let bankcardRouter = require("./routers/bankcard");
let bodyParser = require("body-parser");
let collectRouter = require("./routers/collect");
let registeredOrderRouter = require("./routers/registeredOrder");
const path = require("path");
// const {
//   createProxyMiddleware
// } = require("http-proxy-middleware");
const app = express();

// let lists = require('./static/doctor')

// console.log(lists());

mongoose
  .connect("mongodb://localhost:27017/works")
  .then(() => {
    console.log("数据库连接成功");
  })
  .catch((error) => {
    console.log("数据库连接失败", error);
  });

app.use(
  bodyParser.json({
    limit: "100mb",
  })
);
app.use(
  bodyParser.urlencoded({
    limit: "100mb",
    extended: true,
  })
);
app.use(express.json()); //处理json数据
app.use(express.urlencoded()); //处理a=1&b=2数据

app.use("/api/user", userRouter);
app.use("/api/doctor", doctorRouter);
app.use("/api/cate", cateRouter);
app.use("/api/newsinfo", newsinfoRouter);
app.use("/api/patient", patientRouter);
app.use("/api/follow", followRouter);
app.use("/api/collect", collectRouter);
app.use("/api/bank", bankcardRouter);
app.use("/api/registeredOrder", registeredOrderRouter);

// 响应首页的请求
app.get("/", (req, res) => {
  res.sendFile(path.resolve(__dirname, "./dist/index.html"));
});
// // 响应js资源的请求
app.use("/js", express.static("./dist/js"));
// // 响应css资源的请求
app.use("/css", express.static("./dist/css"));
// // 响应所有静态资源的请求
app.use("/static", express.static("./dist/static"));


// 只有history路由需要配置，hash路由不用配置
// 对于一切响应不了的请求，都响应首页
//首页就会加载js&css。。。
//执行前端的路由，路由加载对应的组件页面。

app.use((req, res) => {
  res.sendFile(path.resolve(__dirname, "./dist/index.html"));
});


app.listen(8888, '192.168.30.2', () => {
  console.log("服务器启动成功---");
})